﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.WorkflowObjects;

namespace FRL.DebtChased.WorkflowEditor.WorkflowItemEditors
{

	/// <summary>
	/// Declaration of ActionBoingPropertiesWnd class
	/// Popup holder to supurt action editing controls for a dialog-type edit
	/// </summary>
	public partial class ActionBoingPropertiesWnd : ChildWindow
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		private ActionBaseCtrl m_childCtrl;

		private WorkflowAction_Base m_action;

		/////////////////////////////////////////////////////////////
		// Construction

		public ActionBoingPropertiesWnd(WorkflowAction_Base action)
		{

			// Initialize member variables
			m_action = action;

			// Initialize resources
			InitializeComponent();

			// Add a control to the window
			if (action is WorkflowAction_PhoneCall)
				m_childCtrl = new PhoneCallCtrl();
			else if (action is WorkflowAction_NotifyManager)
				m_childCtrl = new NotifyManagerCtrl();
			else if (action is WorkflowAction_Popup)
				m_childCtrl = new PopupCtrl();
			else if (action is WorkflowAction_Search)
				m_childCtrl = new SearchCtrl();
			else if (action is WorkflowAction_SendEmail)
				m_childCtrl = new SendEmailCtrl();
			else if (action is WorkflowAction_SendLetterFax)
				m_childCtrl = new SendLetterFaxCtrl();
			else if (action is WorkflowAction_SendSMS)
				m_childCtrl = new SendSMSCtrl();
			else if (action is WorkflowAction_Manual)
				m_childCtrl = new ManualCtrl();
#if DEBUG
			else
				Debug.Assert(false);
#endif // #if DEBUG

			// Set window title
			tbTitle.Text = string.Format("{0} Properties", action.GetBoingLabel().Replace("\n", " "));

			// Add control to grid
			LayoutRoot.Children.Add(m_childCtrl);
			m_childCtrl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
			m_childCtrl.VerticalAlignment = System.Windows.VerticalAlignment.Center;
			m_childCtrl.Width = 720;
			m_childCtrl.Height = 180;
			Grid.SetColumn(m_childCtrl, 0);
			Grid.SetRow(m_childCtrl, 1);

			// Set the controls
			m_childCtrl.InitializeControls();
			m_childCtrl.UpdateControls(m_action);

		}

		/////////////////////////////////////////////////////////////
		// Event Handlers

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{

			// Validate the controls
			List<string> Errors = m_childCtrl.Validate();
			if (Errors != null)
			{

				// Message for user and exit
				MessageBoxes.PopupErrors(Errors);
				return;

			}

			// Update object from controls
			m_childCtrl.UpdateFromControls(ref m_action);

			// Close window
			this.DialogResult = true;

		}

		private void CancelButton_Click(object sender, RoutedEventArgs e)
		{

			// Close window
			this.DialogResult = false;

		}

	}

}

